part of '../repository.dart';

const _kPurchasedItemOtherRevocationReasonValue = 'other';
const _kPurchasedItemRemorseRevocationReasonValue = 'remorse';
const _kPurchasedItemNotReceivedPurchaseRevocationReasonValue = 'not_received_purchase';
const _kPurchasedItemDefectivePurchaseRevocationReasonValue = 'defective_purchase';
const _kPurchasedItemAccidentalPurchaseRevocationReasonValue = 'accidental_purchase';
const _kPurchasedItemFraudRevocationReasonValue = 'fraud';
const _kPurchasedItemFriendlyFraudRevocationReasonValue = 'friendly_fraud';
const _kPurchasedItemChargebackRevocationReasonValue = 'chargeback';

class _TransactionRevocationReasonDto extends Equatable {
  const _TransactionRevocationReasonDto._internal({
    required this.reasonString,
  });

  final String reasonString;

  @override
  List<Object?> get props {
    return [
      reasonString,
    ];
  }

  factory _TransactionRevocationReasonDto.fromString(String s) {
    return _TransactionRevocationReasonDto._internal(
      reasonString: s,
    );
  }

  factory _TransactionRevocationReasonDto.fromEntity(GooglePlayTransactionRevocationReason reason) {
    late final String reasonString;

    if (reason == GooglePlayTransactionRevocationReason.other) {
      reasonString = _kPurchasedItemOtherRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.remorse) {
      reasonString = _kPurchasedItemRemorseRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.notReceivedPurchase) {
      reasonString = _kPurchasedItemNotReceivedPurchaseRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.defectivePurchase) {
      reasonString = _kPurchasedItemDefectivePurchaseRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.accidentalPurchase) {
      reasonString = _kPurchasedItemAccidentalPurchaseRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.fraud) {
      reasonString = _kPurchasedItemFraudRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.friendlyFraud) {
      reasonString = _kPurchasedItemFriendlyFraudRevocationReasonValue;
    } else if (reason == GooglePlayTransactionRevocationReason.chargeback) {
      reasonString = _kPurchasedItemChargebackRevocationReasonValue;
    }

    return _TransactionRevocationReasonDto._internal(
      reasonString: reasonString,
    );
  }

  @override
  String toString() {
    return reasonString;
  }

  GooglePlayTransactionRevocationReason toEntity() {
    if (reasonString == _kPurchasedItemOtherRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.other;
    } else if (reasonString == _kPurchasedItemRemorseRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.remorse;
    } else if (reasonString == _kPurchasedItemNotReceivedPurchaseRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.notReceivedPurchase;
    } else if (reasonString == _kPurchasedItemDefectivePurchaseRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.defectivePurchase;
    } else if (reasonString == _kPurchasedItemAccidentalPurchaseRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.accidentalPurchase;
    } else if (reasonString == _kPurchasedItemFraudRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.fraud;
    } else if (reasonString == _kPurchasedItemFriendlyFraudRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.friendlyFraud;
    } else if (reasonString == _kPurchasedItemChargebackRevocationReasonValue) {
      return GooglePlayTransactionRevocationReason.chargeback;
    }

    throw UnimplementedError();
  }
}
